
<!DOCTYPE HTML>
<html lang="zh-hans" >
<head>
    <meta charset="UTF-8">
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
    <title>手势识别 · 《Flutter实战》</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="baidu-site-verification" content="Y34sAqDKUH"/>
    <meta name="theme-color" content="#ffffff">
    <!--<meta name="description" content="">-->
    <meta name="description" content="《Flutter实战》是Flutter中文网（https://flutterchina.club）开源的电子书，旨在帮助开发者系统化的了解并学习Flutter。">
    <meta name="keywords" content="flutter实战,flutter书籍,flutter电子书,flutter中文网 ">
    <meta name="generator" content="GitBook 3.2.3">
    
    <meta name="author" content="wendux 824783146@qq.com">
    
    
    
    
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/style.css">

    
    
    
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/gitbook-plugin-search-pro/search.css">
    
    
    
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/gitbook-plugin-ace/ace.css">
    
    
    
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/gitbook-plugin-splitter/splitter.css">
    
    
    
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/gitbook-plugin-toggle-chapters/toggle.css">
    
    
    
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/gitbook-plugin-prism/prism.css">
    
    
    
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/gitbook-plugin-donate/plugin.css">
    
    
    
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/gitbook-plugin-fontsettings/website.css">
    
    
    

    

    
        
    
        
    
        
    
        
    
        
    
        
    

    
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="eventbus.html" />
    
    
    <link rel="prev" href="listener.html" />
    

    <style>
        .pull-right > i {
            font-size: 25px;
            color: #777 !important;
            cursor: pointer;

        }

        .pull-right > i:hover {
            color: #777 !important;
        }

        body {
            font-size: 15px !important;
        }

        a[href='../todo.html'], a[href='todo.html'] {
            color: #888 !important;
        }

        .copyright {
            text-align: center;
            margin: 80px 16px 30px 16px;
            padding-top: 16px;
            border-top: #eee 1px solid;
            color: grey;
            font-size: .9em;
        }

        .ad {
            color: white;
            text-align: center;
            background: url(https://img.alicdn.com/tfs/TB1Huu7vMmTBuNjy1XbXXaMrVXa-2880-400.png);
            background-size: cover;
            cursor: pointer;
            margin-bottom: 30px;
            padding: 18px
        }

        .ad:hover {
            opacity: .8;
        }
    </style>
</head>
<body>
<!--<div id="ad" style="display: none">-->
    <!--<div class="ad ad0"-->
         <!--onclick="_track('aliyun','https://promotion.aliyun.com/ntms/yunparter/invite.html?userCode=8hhi4dts')">-->
        <!--<div style="font-size: 1.3em; padding-right: 120px; position: relative; top: 12px">阿里云新春特惠</div>-->
        <!--<div style="color:orange; font-size: 13px">限时红包 最高￥<span style="font-size: 40px">1888</span></div>-->
    <!--</div>-->
    <!--<div class="ad ad1"-->
         <!--onclick="_track('aliyun-puhui','https://promotion.aliyun.com/ntms/act/qwbk.html?spm=5176.11533457.1089570.10.74e877e33jtaGy&userCode=8hhi4dts')">-->
        <!--<div style="font-size: 1.5em;">阿里云全民云计算-新春特惠</div>-->
        <!--<div style="color:orange; font-size: 18px;padding-top: 4px;">普惠上云，云服务器1核1G仅需293元/年</div>-->
    <!--</div>-->
<!--</div>-->

<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    
    
        
        <li>
            <a href="https://flutterchina.club" target="_blank" class="custom-link"><div><img height=20 style='position:relative; top:5px; padding-right:5px ' src='https://cdn.jsdelivr.net/gh/flutterchina/website@1.0/images/favicon.png'/> Flutter中文网</div></a>
        </li>
    
    

    
    <li class="divider"></li>
    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    缘起
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../chapter1/">
            
                <a href="../chapter1/">
            
                    
                    起步
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../chapter1/mobile_development_intro.html">
            
                <a href="../chapter1/mobile_development_intro.html">
            
                    
                    移动开发技术简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../chapter1/flutter_intro.html">
            
                <a href="../chapter1/flutter_intro.html">
            
                    
                    Flutter简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../chapter1/install_flutter.html">
            
                <a href="../chapter1/install_flutter.html">
            
                    
                    搭建Flutter开发环境
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="../chapter1/configuration.html">
            
                <a href="../chapter1/configuration.html">
            
                    
                    常见配置问题
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="../chapter1/dart.html">
            
                <a href="../chapter1/dart.html">
            
                    
                    Dart语言简介
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../chapter2/">
            
                <a href="../chapter2/">
            
                    
                    第一个Flutter应用
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../chapter2/first_flutter_app.html">
            
                <a href="../chapter2/first_flutter_app.html">
            
                    
                    计数器示例
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../chapter2/flutter_router.html">
            
                <a href="../chapter2/flutter_router.html">
            
                    
                    路由管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../chapter2/flutter_package_mgr.html">
            
                <a href="../chapter2/flutter_package_mgr.html">
            
                    
                    包管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../chapter2/flutter_assets_mgr.html">
            
                <a href="../chapter2/flutter_assets_mgr.html">
            
                    
                    资源管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="../chapter2/flutter_app_debug.html">
            
                <a href="../chapter2/flutter_app_debug.html">
            
                    
                    调试Flutter APP
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="../chapter2/thread_model_and_error_report.html">
            
                <a href="../chapter2/thread_model_and_error_report.html">
            
                    
                    Dart线程模型及异常捕获
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../chapter3/">
            
                <a href="../chapter3/">
            
                    
                    基础Widgets
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../chapter3/flutter_widget_intro.html">
            
                <a href="../chapter3/flutter_widget_intro.html">
            
                    
                    Widget简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../chapter3/text.html">
            
                <a href="../chapter3/text.html">
            
                    
                    文本、字体样式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../chapter3/buttons.html">
            
                <a href="../chapter3/buttons.html">
            
                    
                    按钮
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../chapter3/img_and_icon.html">
            
                <a href="../chapter3/img_and_icon.html">
            
                    
                    图片和Icon
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="../chapter3/radio_and_checkbox.html">
            
                <a href="../chapter3/radio_and_checkbox.html">
            
                    
                    单选框和复选框
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="../chapter3/input_and_form.html">
            
                <a href="../chapter3/input_and_form.html">
            
                    
                    输入框和表单
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../chapter4/">
            
                <a href="../chapter4/">
            
                    
                    布局类Widgets
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../chapter4/intro.html">
            
                <a href="../chapter4/intro.html">
            
                    
                    布局类Widgets简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../chapter4/row_and_column.html">
            
                <a href="../chapter4/row_and_column.html">
            
                    
                    线性布局Row、Column
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../chapter4/flex.html">
            
                <a href="../chapter4/flex.html">
            
                    
                    弹性布局Flex
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="../chapter4/wrap_and_flow.html">
            
                <a href="../chapter4/wrap_and_flow.html">
            
                    
                    流式布局Wrap、Flow
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="../chapter4/stack.html">
            
                <a href="../chapter4/stack.html">
            
                    
                    层叠布局Stack、Positioned
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../chapter5/">
            
                <a href="../chapter5/">
            
                    
                    容器类Widgets
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../chapter5/padding.html">
            
                <a href="../chapter5/padding.html">
            
                    
                    Padding
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../chapter5/constrainedbox_and_sizebox.html">
            
                <a href="../chapter5/constrainedbox_and_sizebox.html">
            
                    
                    布局限制类容器ConstrainedBox、SizeBox
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../chapter5/decoratedbox.html">
            
                <a href="../chapter5/decoratedbox.html">
            
                    
                    装饰容器DecoratedBox
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="../chapter5/transform.html">
            
                <a href="../chapter5/transform.html">
            
                    
                    变换Transform
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="../chapter5/container.html">
            
                <a href="../chapter5/container.html">
            
                    
                    Container容器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.6" data-path="../chapter5/material_scaffold.html">
            
                <a href="../chapter5/material_scaffold.html">
            
                    
                    Scaffold、TabBar、底部导航
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../chapter6/">
            
                <a href="../chapter6/">
            
                    
                    可滚动Widgets
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../chapter6/intro.html">
            
                <a href="../chapter6/intro.html">
            
                    
                    可滚动Widgets简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../chapter6/single_child_scrollview.html">
            
                <a href="../chapter6/single_child_scrollview.html">
            
                    
                    SingleChildScrollView
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="../chapter6/listview.html">
            
                <a href="../chapter6/listview.html">
            
                    
                    ListView
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.4" data-path="../chapter6/gridview.html">
            
                <a href="../chapter6/gridview.html">
            
                    
                    GridView
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.5" data-path="../chapter6/custom_scrollview.html">
            
                <a href="../chapter6/custom_scrollview.html">
            
                    
                    CustomScrollView
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.6" data-path="../chapter6/scroll_controller.html">
            
                <a href="../chapter6/scroll_controller.html">
            
                    
                    滚动监听及控制ScrollController
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../chapter7/">
            
                <a href="../chapter7/">
            
                    
                    功能型Widgets
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="../chapter7/willpopscope.html">
            
                <a href="../chapter7/willpopscope.html">
            
                    
                    导航返回拦截-WillPopScope
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="../chapter7/inherited_widget.html">
            
                <a href="../chapter7/inherited_widget.html">
            
                    
                    数据共享-InheritedWidget
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="../chapter7/theme.html">
            
                <a href="../chapter7/theme.html">
            
                    
                    主题-Theme
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="./">
            
                <a href="./">
            
                    
                    事件处理与通知
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.1" data-path="listener.html">
            
                <a href="listener.html">
            
                    
                    原始指针事件处理
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.9.2" data-path="gesture.html">
            
                <a href="gesture.html">
            
                    
                    手势识别
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.3" data-path="eventbus.html">
            
                <a href="eventbus.html">
            
                    
                    全局事件总线
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.4" data-path="notification.html">
            
                <a href="notification.html">
            
                    
                    通知Notification
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../chapter9/">
            
                <a href="../chapter9/">
            
                    
                    动画
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.10.1" data-path="../chapter9/intro.html">
            
                <a href="../chapter9/intro.html">
            
                    
                    Flutter动画简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.2" data-path="../chapter9/animation_structure.html">
            
                <a href="../chapter9/animation_structure.html">
            
                    
                    动画结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.3" data-path="../chapter9/route_transition.html">
            
                <a href="../chapter9/route_transition.html">
            
                    
                    自定义路由过渡动画
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.4" data-path="../chapter9/hero.html">
            
                <a href="../chapter9/hero.html">
            
                    
                    Hero动画
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.5" data-path="../chapter9/stagger_animation.html">
            
                <a href="../chapter9/stagger_animation.html">
            
                    
                    交错动画
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="../chapter13/">
            
                <a href="../chapter13/">
            
                    
                    自定义Widget
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.11.1" data-path="../chapter13/intro.html">
            
                <a href="../chapter13/intro.html">
            
                    
                    自定义Widget方法简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.2" data-path="../chapter13/combine.html">
            
                <a href="../chapter13/combine.html">
            
                    
                    通过组合现有Widget实现
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.3" data-path="../chapter13/turn_box.html">
            
                <a href="../chapter13/turn_box.html">
            
                    
                    实例：TurnBox
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.4" data-path="../chapter13/custom_paint.html">
            
                <a href="../chapter13/custom_paint.html">
            
                    
                    CustomPaint与Canvas
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.5" data-path="../chapter13/gradient_circular_progress_demo.html">
            
                <a href="../chapter13/gradient_circular_progress_demo.html">
            
                    
                    实例：圆形渐变进度条(自绘)
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="../chapter10/">
            
                <a href="../chapter10/">
            
                    
                    文件操作与网络请求
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.12.1" data-path="../chapter10/file_operation.html">
            
                <a href="../chapter10/file_operation.html">
            
                    
                    文件操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.2" data-path="../chapter10/http.html">
            
                <a href="../chapter10/http.html">
            
                    
                    Http请求-HttpClient
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.3" data-path="../chapter10/dio.html">
            
                <a href="../chapter10/dio.html">
            
                    
                    Http请求-Dio package
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.4" data-path="../chapter10/download_with_chunks.html">
            
                <a href="../chapter10/download_with_chunks.html">
            
                    
                    实例：Http分块下载
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.5" data-path="../chapter10/websocket.html">
            
                <a href="../chapter10/websocket.html">
            
                    
                    WebSocket
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.6" data-path="../chapter10/socket.html">
            
                <a href="../chapter10/socket.html">
            
                    
                    使用Socket API
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.7" data-path="../chapter10/json_model.html">
            
                <a href="../chapter10/json_model.html">
            
                    
                    Json转Model
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="../chapter11/">
            
                <a href="../chapter11/">
            
                    
                    包与插件
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.13.1" data-path="../chapter11/develop_package.html">
            
                <a href="../chapter11/develop_package.html">
            
                    
                    开发package
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.2" data-path="../chapter11/platform-channel.html">
            
                <a href="../chapter11/platform-channel.html">
            
                    
                    插件开发：平台通道简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.3" data-path="../chapter11/android_implement.html">
            
                <a href="../chapter11/android_implement.html">
            
                    
                    插件开发：实现Android端API
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.4" data-path="../chapter11/ios_implement.html">
            
                <a href="../chapter11/ios_implement.html">
            
                    
                    插件开发：实现IOS端API
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.5" data-path="../todo.html">
            
                <a href="../todo.html">
            
                    
                    系统能力调用
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="../chapter12/">
            
                <a href="../chapter12/">
            
                    
                    国际化
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.14.1" data-path="../chapter12/multi_languages_support.html">
            
                <a href="../chapter12/multi_languages_support.html">
            
                    
                    让App支持多语言
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.2" data-path="../chapter12/locallization_implement.html">
            
                <a href="../chapter12/locallization_implement.html">
            
                    
                    实现Localizations
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.3" data-path="../chapter12/intl.html">
            
                <a href="../chapter12/intl.html">
            
                    
                    使用Intl包
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="../chapter14/">
            
                <a href="../chapter14/">
            
                    
                    Flutter核心原理
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.15.1" data-path="../chapter14/flutter_ui_system.html">
            
                <a href="../chapter14/flutter_ui_system.html">
            
                    
                    Flutter UI系统
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.2" data-path="../chapter14/element_buildcontext.html">
            
                <a href="../chapter14/element_buildcontext.html">
            
                    
                    Element和BuildContext
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.3" data-path="../chapter14/render_object.html">
            
                <a href="../chapter14/render_object.html">
            
                    
                    RenderObject与RenderBox
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.4" data-path="../chapter14/flutter_app_startup.html">
            
                <a href="../chapter14/flutter_app_startup.html">
            
                    
                    Flutter从启动到显示
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="../todo.html">
            
                <a href="../todo.html">
            
                    
                    Flutter资源汇总
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    
    <a class="btn pull-right" aria-label="GitHub">
        <i class="fa fa-edit" title="编辑本文"></i>
    </a>
    <a class="btn pull-right" aria-label="GitHub" href="https://github.com/flutterchina/flutter-in-action">
        <i class="fa fa-github" title="查看本书开源项目"></i>
    </a>
    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >手势识别</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h2 id="&#x624B;&#x52BF;&#x8BC6;&#x522B;gesturedetector">&#x624B;&#x52BF;&#x8BC6;&#x522B;GestureDetector</h2>
<p>GestureDetector&#x662F;&#x4E00;&#x4E2A;&#x7528;&#x4E8E;&#x624B;&#x52BF;&#x8BC6;&#x522B;&#x7684;&#x529F;&#x80FD;&#x6027;Widget&#xFF0C;&#x6211;&#x4EEC;&#x901A;&#x8FC7;&#x5B83;&#x53EF;&#x4EE5;&#x6765;&#x8BC6;&#x522B;&#x5404;&#x79CD;&#x624B;&#x52BF;&#xFF0C;&#x5B83;&#x662F;&#x6307;&#x9488;&#x4E8B;&#x4EF6;&#x7684;&#x8BED;&#x4E49;&#x5316;&#x5C01;&#x88C5;&#xFF0C;&#x63A5;&#x4E0B;&#x6765;&#x6211;&#x4EEC;&#x8BE6;&#x7EC6;&#x4ECB;&#x7ECD;&#x4E00;&#x4E0B;&#x5404;&#x79CD;&#x624B;&#x52BF;&#x8BC6;&#x522B;&#xFF1A;</p>
<h3 id="&#x70B9;&#x51FB;&#x3001;&#x53CC;&#x51FB;&#x3001;&#x957F;&#x6309;">&#x70B9;&#x51FB;&#x3001;&#x53CC;&#x51FB;&#x3001;&#x957F;&#x6309;</h3>
<p>&#x6211;&#x4EEC;&#x901A;&#x8FC7;GestureDetector&#x5BF9;Container&#x8FDB;&#x884C;&#x624B;&#x52BF;&#x8BC6;&#x522B;&#xFF0C;&#x89E6;&#x53D1;&#x76F8;&#x5E94;&#x4E8B;&#x4EF6;&#x540E;&#xFF0C;&#x5728;Container&#x4E0A;&#x663E;&#x793A;&#x4E8B;&#x4EF6;&#x540D;&#xFF0C;&#x4E3A;&#x4E86;&#x589E;&#x5927;&#x70B9;&#x51FB;&#x533A;&#x57DF;&#xFF0C;&#x5C06;Container&#x8BBE;&#x7F6E;&#x4E3A;200&#xD7;100&#xFF0C;&#x4EE3;&#x7801;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre class="language-"><code class="lang-dart">
<span class="token keyword">class</span> <span class="token class-name">GestureDetectorTestRoute</span> <span class="token keyword">extends</span> <span class="token class-name">StatefulWidget</span> <span class="token punctuation">{</span>
  <span class="token metadata symbol">@override</span>
  _GestureDetectorTestRouteState <span class="token function">createState</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">&gt;</span>
      <span class="token keyword">new</span> <span class="token class-name">_GestureDetectorTestRouteState</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token keyword">class</span> <span class="token class-name">_GestureDetectorTestRouteState</span> <span class="token keyword">extends</span> <span class="token class-name">State</span><span class="token operator">&lt;</span>GestureDetectorTestRoute<span class="token operator">&gt;</span> <span class="token punctuation">{</span>
  String _operation <span class="token operator">=</span> <span class="token string">&quot;No Gesture detected!&quot;</span><span class="token punctuation">;</span> <span class="token comment">//&#x4FDD;&#x5B58;&#x4E8B;&#x4EF6;&#x540D;</span>
  <span class="token metadata symbol">@override</span>
  Widget <span class="token function">build</span><span class="token punctuation">(</span>BuildContext context<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token function">Center</span><span class="token punctuation">(</span>
      child<span class="token punctuation">:</span> <span class="token function">GestureDetector</span><span class="token punctuation">(</span>
        child<span class="token punctuation">:</span> <span class="token function">Container</span><span class="token punctuation">(</span>
          alignment<span class="token punctuation">:</span> Alignment<span class="token punctuation">.</span>center<span class="token punctuation">,</span>
          color<span class="token punctuation">:</span> Colors<span class="token punctuation">.</span>blue<span class="token punctuation">,</span>
          width<span class="token punctuation">:</span> <span class="token number">200.0</span><span class="token punctuation">,</span> 
          height<span class="token punctuation">:</span> <span class="token number">100.0</span><span class="token punctuation">,</span>
          child<span class="token punctuation">:</span> <span class="token function">Text</span><span class="token punctuation">(</span>_operation<span class="token punctuation">,</span>
            style<span class="token punctuation">:</span> <span class="token function">TextStyle</span><span class="token punctuation">(</span>color<span class="token punctuation">:</span> Colors<span class="token punctuation">.</span>white<span class="token punctuation">)</span><span class="token punctuation">,</span>
          <span class="token punctuation">)</span><span class="token punctuation">,</span>
        <span class="token punctuation">)</span><span class="token punctuation">,</span>
        onTap<span class="token punctuation">:</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">&gt;</span> <span class="token function">updateText</span><span class="token punctuation">(</span><span class="token string">&quot;Tap&quot;</span><span class="token punctuation">)</span><span class="token punctuation">,</span><span class="token comment">//&#x70B9;&#x51FB;</span>
        onDoubleTap<span class="token punctuation">:</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">&gt;</span> <span class="token function">updateText</span><span class="token punctuation">(</span><span class="token string">&quot;DoubleTap&quot;</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token comment">//&#x53CC;&#x51FB;</span>
        onLongPress<span class="token punctuation">:</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">&gt;</span> <span class="token function">updateText</span><span class="token punctuation">(</span><span class="token string">&quot;LongPress&quot;</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token comment">//&#x957F;&#x6309;</span>
      <span class="token punctuation">)</span><span class="token punctuation">,</span>
    <span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>

  <span class="token keyword">void</span> <span class="token function">updateText</span><span class="token punctuation">(</span>String text<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token comment">//&#x66F4;&#x65B0;&#x663E;&#x793A;&#x7684;&#x4E8B;&#x4EF6;&#x540D;</span>
    <span class="token function">setState</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      _operation <span class="token operator">=</span> text<span class="token punctuation">;</span>
    <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x8FD0;&#x884C;&#x6548;&#x679C;&#xFF1A;</p>
<p><img src="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action@1.0/docs/imgs/image-20180914123650324.png" alt="image-20180914123650324"></p>
<p><strong>&#x6CE8;&#x610F;</strong>&#xFF1A; &#x5F53;&#x540C;&#x65F6;&#x76D1;&#x542C;<code>onTap</code>&#x548C;<code>onDoubleTap</code>&#x4E8B;&#x4EF6;&#x65F6;&#xFF0C;&#x5F53;&#x7528;&#x6237;&#x89E6;&#x53D1;tap&#x4E8B;&#x4EF6;&#x65F6;&#xFF0C;&#x4F1A;&#x6709;200&#x6BEB;&#x79D2;&#x5DE6;&#x53F3;&#x7684;&#x5EF6;&#x65F6;&#xFF0C;&#x8FD9;&#x662F;&#x56E0;&#x4E3A;&#x5F53;&#x7528;&#x6237;&#x70B9;&#x51FB;&#x5B8C;&#x4E4B;&#x540E;&#x5F88;&#x53EF;&#x80FD;&#x4F1A;&#x518D;&#x6B21;&#x70B9;&#x51FB;&#x4EE5;&#x89E6;&#x53D1;&#x53CC;&#x51FB;&#x4E8B;&#x4EF6;&#xFF0C;&#x6240;&#x4EE5;GestureDetector&#x4F1A;&#x7B49;&#x4E00;&#x65AD;&#x65F6;&#x95F4;&#x6765;&#x786E;&#x5B9A;&#x662F;&#x5426;&#x4E3A;&#x53CC;&#x51FB;&#x4E8B;&#x4EF6;&#x3002;&#x5982;&#x679C;&#x7528;&#x6237;&#x53EA;&#x76D1;&#x542C;&#x4E86;<code>onTap</code>&#xFF08;&#x6CA1;&#x6709;&#x76D1;&#x542C;<code>onDoubleTap</code>&#xFF09;&#x4E8B;&#x4EF6;&#x65F6;&#xFF0C;&#x5219;&#x6CA1;&#x6709;&#x5EF6;&#x65F6;&#x3002;</p>
<h3 id="&#x62D6;&#x52A8;&#x3001;&#x6ED1;&#x52A8;">&#x62D6;&#x52A8;&#x3001;&#x6ED1;&#x52A8;</h3>
<p>&#x4E00;&#x6B21;&#x5B8C;&#x6574;&#x7684;&#x624B;&#x52BF;&#x8FC7;&#x7A0B;&#x662F;&#x6307;&#x7528;&#x6237;&#x624B;&#x6307;&#x6309;&#x4E0B;&#x5230;&#x62AC;&#x8D77;&#x7684;&#x6574;&#x4E2A;&#x8FC7;&#x7A0B;&#xFF0C;&#x671F;&#x95F4;&#xFF0C;&#x7528;&#x6237;&#x6309;&#x4E0B;&#x624B;&#x6307;&#x540E;&#x53EF;&#x80FD;&#x4F1A;&#x79FB;&#x52A8;&#xFF0C;&#x4E5F;&#x53EF;&#x80FD;&#x4E0D;&#x4F1A;&#x79FB;&#x52A8;&#x3002;GestureDetector&#x5BF9;&#x4E8E;&#x62D6;&#x52A8;&#x548C;&#x6ED1;&#x52A8;&#x4E8B;&#x4EF6;&#x662F;&#x6CA1;&#x6709;&#x533A;&#x5206;&#x7684;&#xFF0C;&#x4ED6;&#x4EEC;&#x672C;&#x8D28;&#x4E0A;&#x662F;&#x4E00;&#x6837;&#x7684;&#x3002;GestureDetector&#x4F1A;&#x5C06;&#x8981;&#x76D1;&#x542C;&#x7684;widget&#x7684;&#x539F;&#x70B9;&#xFF08;&#x5DE6;&#x4E0A;&#x89D2;&#xFF09;&#x4F5C;&#x4E3A;&#x672C;&#x6B21;&#x624B;&#x52BF;&#x7684;&#x539F;&#x70B9;&#xFF0C;&#x5F53;&#x7528;&#x6237;&#x5728;&#x76D1;&#x542C;&#x7684;widget&#x4E0A;&#x6309;&#x4E0B;&#x624B;&#x6307;&#x65F6;&#xFF0C;&#x624B;&#x52BF;&#x8BC6;&#x522B;&#x5C31;&#x4F1A;&#x5F00;&#x59CB;&#x3002;&#x4E0B;&#x9762;&#x6211;&#x4EEC;&#x770B;&#x4E00;&#x4E2A;&#x62D6;&#x52A8;&#x5706;&#x5F62;&#x5B57;&#x6BCD;A&#x7684;&#x793A;&#x4F8B;&#xFF1A;</p>
<pre class="language-"><code class="lang-dart"><span class="token keyword">class</span> <span class="token class-name">_Drag</span> <span class="token keyword">extends</span> <span class="token class-name">StatefulWidget</span> <span class="token punctuation">{</span>
  <span class="token metadata symbol">@override</span>
  _DragState <span class="token function">createState</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">&gt;</span> <span class="token keyword">new</span> <span class="token class-name">_DragState</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token keyword">class</span> <span class="token class-name">_DragState</span> <span class="token keyword">extends</span> <span class="token class-name">State</span><span class="token operator">&lt;</span>_Drag<span class="token operator">&gt;</span> <span class="token keyword">with</span> SingleTickerProviderStateMixin <span class="token punctuation">{</span>
  double _top <span class="token operator">=</span> <span class="token number">0.0</span><span class="token punctuation">;</span> <span class="token comment">//&#x8DDD;&#x9876;&#x90E8;&#x7684;&#x504F;&#x79FB;</span>
  double _left <span class="token operator">=</span> <span class="token number">0.0</span><span class="token punctuation">;</span><span class="token comment">//&#x8DDD;&#x5DE6;&#x8FB9;&#x7684;&#x504F;&#x79FB;</span>

  <span class="token metadata symbol">@override</span>
  Widget <span class="token function">build</span><span class="token punctuation">(</span>BuildContext context<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token function">Stack</span><span class="token punctuation">(</span>
      children<span class="token punctuation">:</span> <span class="token operator">&lt;</span>Widget<span class="token operator">&gt;</span><span class="token punctuation">[</span>
        <span class="token function">Positioned</span><span class="token punctuation">(</span>
          top<span class="token punctuation">:</span> _top<span class="token punctuation">,</span>
          left<span class="token punctuation">:</span> _left<span class="token punctuation">,</span>
          child<span class="token punctuation">:</span> <span class="token function">GestureDetector</span><span class="token punctuation">(</span>
            child<span class="token punctuation">:</span> <span class="token function">CircleAvatar</span><span class="token punctuation">(</span>child<span class="token punctuation">:</span> <span class="token function">Text</span><span class="token punctuation">(</span><span class="token string">&quot;A&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
            <span class="token comment">//&#x624B;&#x6307;&#x6309;&#x4E0B;&#x65F6;&#x4F1A;&#x89E6;&#x53D1;&#x6B64;&#x56DE;&#x8C03;</span>
            onPanDown<span class="token punctuation">:</span> <span class="token punctuation">(</span>DragDownDetails e<span class="token punctuation">)</span> <span class="token punctuation">{</span>
              <span class="token comment">//&#x6253;&#x5370;&#x624B;&#x6307;&#x6309;&#x4E0B;&#x7684;&#x4F4D;&#x7F6E;(&#x76F8;&#x5BF9;&#x4E8E;&#x5C4F;&#x5E55;)</span>
              <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&quot;&#x7528;&#x6237;&#x624B;&#x6307;&#x6309;&#x4E0B;&#xFF1A;${e.globalPosition}&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span><span class="token punctuation">,</span>
            <span class="token comment">//&#x624B;&#x6307;&#x6ED1;&#x52A8;&#x65F6;&#x4F1A;&#x89E6;&#x53D1;&#x6B64;&#x56DE;&#x8C03;</span>
            onPanUpdate<span class="token punctuation">:</span> <span class="token punctuation">(</span>DragUpdateDetails e<span class="token punctuation">)</span> <span class="token punctuation">{</span>
              <span class="token comment">//&#x7528;&#x6237;&#x624B;&#x6307;&#x6ED1;&#x52A8;&#x65F6;&#xFF0C;&#x66F4;&#x65B0;&#x504F;&#x79FB;&#xFF0C;&#x91CD;&#x65B0;&#x6784;&#x5EFA;</span>
              <span class="token function">setState</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                _left <span class="token operator">+=</span> e<span class="token punctuation">.</span>delta<span class="token punctuation">.</span>dx<span class="token punctuation">;</span>
                _top <span class="token operator">+=</span> e<span class="token punctuation">.</span>delta<span class="token punctuation">.</span>dy<span class="token punctuation">;</span>
              <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span><span class="token punctuation">,</span>
            onPanEnd<span class="token punctuation">:</span> <span class="token punctuation">(</span>DragEndDetails e<span class="token punctuation">)</span><span class="token punctuation">{</span>
              <span class="token comment">//&#x6253;&#x5370;&#x6ED1;&#x52A8;&#x7ED3;&#x675F;&#x65F6;&#x5728;x&#x3001;y&#x8F74;&#x4E0A;&#x7684;&#x901F;&#x5EA6;</span>
              <span class="token function">print</span><span class="token punctuation">(</span>e<span class="token punctuation">.</span>velocity<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span><span class="token punctuation">,</span>
          <span class="token punctuation">)</span><span class="token punctuation">,</span>
        <span class="token punctuation">)</span>
      <span class="token punctuation">]</span><span class="token punctuation">,</span>
    <span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x8FD0;&#x884C;&#x540E;&#xFF0C;&#x5C31;&#x53EF;&#x4EE5;&#x5728;&#x4EFB;&#x610F;&#x65B9;&#x5411;&#x62D6;&#x52A8;&#x4E86;&#xFF1A;</p>
<p><img src="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action@1.0/docs/imgs/image-20180914135811570.png" alt="image-20180914135811570"></p>
<p>&#x65E5;&#x5FD7;&#xFF1A;</p>
<pre class="language-"><code>I/flutter ( 8513): &#x7528;&#x6237;&#x624B;&#x6307;&#x6309;&#x4E0B;&#xFF1A;Offset(26.3, 101.8)
I/flutter ( 8513): Velocity(235.5, 125.8)
</code></pre><p>&#x4EE3;&#x7801;&#x89E3;&#x91CA;&#xFF1A;</p>
<ul>
<li><code>DragDownDetails.globalPosition</code>&#xFF1A;&#x5F53;&#x7528;&#x6237;&#x6309;&#x4E0B;&#x65F6;&#xFF0C;&#x6B64;&#x5C5E;&#x6027;&#x4E3A;&#x7528;&#x6237;&#x6309;&#x4E0B;&#x7684;&#x4F4D;&#x7F6E;&#x76F8;&#x5BF9;&#x4E8E;<strong>&#x5C4F;&#x5E55;</strong>(&#x800C;&#x975E;&#x7236;widget)&#x539F;&#x70B9;(&#x5DE6;&#x4E0A;&#x89D2;)&#x7684;&#x504F;&#x79FB;&#x3002;</li>
<li><code>DragUpdateDetails.delta</code>&#xFF1A;&#x5F53;&#x7528;&#x6237;&#x5728;&#x5C4F;&#x5E55;&#x4E0A;&#x6ED1;&#x52A8;&#x65F6;&#xFF0C;&#x4F1A;&#x89E6;&#x53D1;&#x591A;&#x6B21;Update&#x4E8B;&#x4EF6;&#xFF0C;<code>delta</code>&#x6307;&#x4E00;&#x6B21;Update&#x4E8B;&#x4EF6;&#x7684;&#x6ED1;&#x52A8;&#x7684;&#x504F;&#x79FB;&#x91CF;&#x3002;</li>
<li><code>DragEndDetails.velocity</code>&#xFF1A;&#x8BE5;&#x5C5E;&#x6027;&#x4EE3;&#x8868;&#x7528;&#x6237;&#x62AC;&#x8D77;&#x624B;&#x6307;&#x65F6;&#x7684;&#x6ED1;&#x52A8;&#x901F;&#x5EA6;(&#x5305;&#x542B;x&#x3001;y&#x4E24;&#x4E2A;&#x8F74;&#x7684;&#xFF09;&#xFF0C;&#x793A;&#x4F8B;&#x4E2D;&#x5E76;&#x6CA1;&#x6709;&#x5904;&#x7406;&#x624B;&#x6307;&#x62AC;&#x8D77;&#x65F6;&#x7684;&#x901F;&#x5EA6;&#xFF0C;&#x5E38;&#x89C1;&#x7684;&#x6548;&#x679C;&#x662F;&#x6839;&#x636E;&#x7528;&#x6237;&#x62AC;&#x8D77;&#x624B;&#x6307;&#x65F6;&#x7684;&#x901F;&#x5EA6;&#x505A;&#x4E00;&#x4E2A;&#x51CF;&#x901F;&#x52A8;&#x753B;&#x3002;</li>
</ul>
<h3 id="&#x5355;&#x4E00;&#x65B9;&#x5411;&#x62D6;&#x52A8;">&#x5355;&#x4E00;&#x65B9;&#x5411;&#x62D6;&#x52A8;</h3>
<p>&#x5728;&#x672C;&#x793A;&#x4F8B;&#x4E2D;&#xFF0C;&#x662F;&#x53EF;&#x4EE5;&#x671D;&#x4EFB;&#x610F;&#x65B9;&#x5411;&#x62D6;&#x52A8;&#x7684;&#xFF0C;&#x4F46;&#x662F;&#x5728;&#x5F88;&#x591A;&#x573A;&#x666F;&#xFF0C;&#x6211;&#x4EEC;&#x53EA;&#x9700;&#x8981;&#x6CBF;&#x4E00;&#x4E2A;&#x65B9;&#x5411;&#x6765;&#x62D6;&#x52A8;&#xFF0C;&#x5982;&#x4E00;&#x4E2A;&#x5782;&#x76F4;&#x65B9;&#x5411;&#x7684;&#x5217;&#x8868;&#xFF0C;GestureDetector&#x53EF;&#x4EE5;&#x53EA;&#x8BC6;&#x522B;&#x7279;&#x5B9A;&#x65B9;&#x5411;&#x7684;&#x624B;&#x52BF;&#x4E8B;&#x4EF6;&#xFF0C;&#x6211;&#x4EEC;&#x5C06;&#x4E0A;&#x9762;&#x7684;&#x4F8B;&#x5B50;&#x6539;&#x4E3A;&#x53EA;&#x80FD;&#x6CBF;&#x5782;&#x76F4;&#x65B9;&#x5411;&#x62D6;&#x52A8;&#xFF1A;</p>
<pre class="language-"><code class="lang-dart"><span class="token keyword">class</span> <span class="token class-name">_DragVertical</span> <span class="token keyword">extends</span> <span class="token class-name">StatefulWidget</span> <span class="token punctuation">{</span>
  <span class="token metadata symbol">@override</span>
  _DragVerticalState <span class="token function">createState</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">&gt;</span> <span class="token keyword">new</span> <span class="token class-name">_DragVerticalState</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token keyword">class</span> <span class="token class-name">_DragVerticalState</span> <span class="token keyword">extends</span> <span class="token class-name">State</span><span class="token operator">&lt;</span>_DragVertical<span class="token operator">&gt;</span> <span class="token punctuation">{</span>
  double _top <span class="token operator">=</span> <span class="token number">0.0</span><span class="token punctuation">;</span>

  <span class="token metadata symbol">@override</span>
  Widget <span class="token function">build</span><span class="token punctuation">(</span>BuildContext context<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token function">Stack</span><span class="token punctuation">(</span>
      children<span class="token punctuation">:</span> <span class="token operator">&lt;</span>Widget<span class="token operator">&gt;</span><span class="token punctuation">[</span>
        <span class="token function">Positioned</span><span class="token punctuation">(</span>
          top<span class="token punctuation">:</span> _top<span class="token punctuation">,</span>
          child<span class="token punctuation">:</span> <span class="token function">GestureDetector</span><span class="token punctuation">(</span>
            child<span class="token punctuation">:</span> <span class="token function">CircleAvatar</span><span class="token punctuation">(</span>child<span class="token punctuation">:</span> <span class="token function">Text</span><span class="token punctuation">(</span><span class="token string">&quot;A&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
            <span class="token comment">//&#x5782;&#x76F4;&#x65B9;&#x5411;&#x62D6;&#x52A8;&#x4E8B;&#x4EF6;</span>
            onVerticalDragUpdate<span class="token punctuation">:</span> <span class="token punctuation">(</span>DragUpdateDetails details<span class="token punctuation">)</span> <span class="token punctuation">{</span>
              <span class="token function">setState</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                _top <span class="token operator">+=</span> details<span class="token punctuation">.</span>delta<span class="token punctuation">.</span>dy<span class="token punctuation">;</span>
              <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
          <span class="token punctuation">)</span><span class="token punctuation">,</span>
        <span class="token punctuation">)</span>
      <span class="token punctuation">]</span><span class="token punctuation">,</span>
    <span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x8FD9;&#x6837;&#x5C31;&#x53EA;&#x80FD;&#x5728;&#x5782;&#x76F4;&#x65B9;&#x5411;&#x62D6;&#x52A8;&#x4E86;&#xFF0C;&#x5982;&#x679C;&#x53EA;&#x60F3;&#x5728;&#x6C34;&#x5E73;&#x65B9;&#x5411;&#x6ED1;&#x52A8;&#x540C;&#x7406;&#x3002;</p>
<h3 id="&#x7F29;&#x653E;">&#x7F29;&#x653E;</h3>
<p>GestureDetector&#x53EF;&#x4EE5;&#x76D1;&#x542C;&#x7F29;&#x653E;&#x4E8B;&#x4EF6;&#xFF0C;&#x4E0B;&#x9762;&#x793A;&#x4F8B;&#x6F14;&#x793A;&#x4E86;&#x4E00;&#x4E2A;&#x7B80;&#x5355;&#x7684;&#x56FE;&#x7247;&#x7F29;&#x653E;&#x6548;&#x679C;&#xFF1A;</p>
<pre class="language-"><code class="lang-dart"><span class="token keyword">class</span> <span class="token class-name">_ScaleTestRouteState</span> <span class="token keyword">extends</span> <span class="token class-name">State</span><span class="token operator">&lt;</span>_ScaleTestRoute<span class="token operator">&gt;</span> <span class="token punctuation">{</span>
  double _width <span class="token operator">=</span> <span class="token number">200.0</span><span class="token punctuation">;</span> <span class="token comment">//&#x901A;&#x8FC7;&#x4FEE;&#x6539;&#x56FE;&#x7247;&#x5BBD;&#x5EA6;&#x6765;&#x8FBE;&#x5230;&#x7F29;&#x653E;&#x6548;&#x679C;</span>

  <span class="token metadata symbol">@override</span>
  Widget <span class="token function">build</span><span class="token punctuation">(</span>BuildContext context<span class="token punctuation">)</span> <span class="token punctuation">{</span>
   <span class="token keyword">return</span> <span class="token function">Center</span><span class="token punctuation">(</span>
     child<span class="token punctuation">:</span> <span class="token function">GestureDetector</span><span class="token punctuation">(</span>
        <span class="token comment">//&#x6307;&#x5B9A;&#x5BBD;&#x5EA6;&#xFF0C;&#x9AD8;&#x5EA6;&#x81EA;&#x9002;&#x5E94;</span>
        child<span class="token punctuation">:</span> Image<span class="token punctuation">.</span><span class="token function">asset</span><span class="token punctuation">(</span><span class="token string">&quot;./images/sea.png&quot;</span><span class="token punctuation">,</span> width<span class="token punctuation">:</span> _width<span class="token punctuation">)</span><span class="token punctuation">,</span>
        onScaleUpdate<span class="token punctuation">:</span> <span class="token punctuation">(</span>ScaleUpdateDetails details<span class="token punctuation">)</span> <span class="token punctuation">{</span>
          <span class="token function">setState</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token comment">//&#x7F29;&#x653E;&#x500D;&#x6570;&#x5728;0.8&#x5230;10&#x500D;&#x4E4B;&#x95F4;</span>
            _width<span class="token operator">=</span><span class="token number">200</span><span class="token operator">*</span>details<span class="token punctuation">.</span>scale<span class="token punctuation">.</span><span class="token function">clamp</span><span class="token punctuation">(</span><span class="token number">.8</span><span class="token punctuation">,</span> <span class="token number">10.0</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
          <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span><span class="token punctuation">,</span>
      <span class="token punctuation">)</span><span class="token punctuation">,</span>
   <span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x8FD0;&#x884C;&#x6548;&#x679C;&#xFF1A;</p>
<p><img src="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action@1.0/docs/imgs/image-20180914184749975.png" alt="image-20180914184749975"></p>
<p>&#x73B0;&#x5728;&#x5728;&#x56FE;&#x7247;&#x4E0A;&#x53CC;&#x6307;&#x5F20;&#x5F00;&#x3001;&#x6536;&#x7F29;&#x5C31;&#x53EF;&#x4EE5;&#x653E;&#x5927;&#x3001;&#x7F29;&#x5C0F;&#x56FE;&#x7247;&#x3002;&#x672C;&#x793A;&#x4F8B;&#x6BD4;&#x8F83;&#x7B80;&#x5355;&#xFF0C;&#x5B9E;&#x9645;&#x4E2D;&#x6211;&#x4EEC;&#x901A;&#x5E38;&#x8FD8;&#x9700;&#x8981;&#x4E00;&#x4E9B;&#x5176;&#x5B83;&#x529F;&#x80FD;&#xFF0C;&#x5982;&#x53CC;&#x51FB;&#x653E;&#x5927;&#x6216;&#x7F29;&#x5C0F;&#x4E00;&#x5B9A;&#x500D;&#x6570;&#x3001;&#x53CC;&#x6307;&#x5F20;&#x5F00;&#x79BB;&#x5F00;&#x5C4F;&#x5E55;&#x65F6;&#x6267;&#x884C;&#x4E00;&#x4E2A;&#x51CF;&#x901F;&#x653E;&#x5927;&#x52A8;&#x753B;&#x7B49;&#xFF0C;&#x6211;&#x4EEC;&#x5C06;&#x5728;&#x540E;&#x9762;&#x201C;&#x52A8;&#x753B;&#x201D;&#x4E00;&#x7AE0;&#x4E2D;&#x5B9E;&#x73B0;&#x4E00;&#x4E2A;&#x5B8C;&#x6574;&#x7684;&#x7F29;&#x653E;Widget&#x3002;</p>
<h3 id="gesturerecognizer">GestureRecognizer</h3>
<p>GestureDetector&#x5185;&#x90E8;&#x662F;&#x4F7F;&#x7528;&#x4E00;&#x4E2A;&#x6216;&#x591A;&#x4E2A;GestureRecognizer&#x6765;&#x8BC6;&#x522B;&#x5404;&#x79CD;&#x624B;&#x52BF;&#x7684;&#xFF0C;&#x800C;GestureRecognizer&#x7684;&#x4F5C;&#x7528;&#x5C31;&#x662F;&#x901A;&#x8FC7;Listener&#x6765;&#x5C06;&#x539F;&#x59CB;&#x6307;&#x9488;&#x4E8B;&#x4EF6;&#x8F6C;&#x6362;&#x4E3A;&#x8BED;&#x4E49;&#x624B;&#x52BF;&#xFF0C;GestureDetector&#x76F4;&#x63A5;&#x53EF;&#x4EE5;&#x63A5;&#x6536;&#x4E00;&#x4E2A;&#x5B50;Widget&#x3002;GestureRecognizer&#x662F;&#x4E00;&#x4E2A;&#x62BD;&#x8C61;&#x7C7B;&#xFF0C;&#x4E00;&#x79CD;&#x624B;&#x52BF;&#x7684;&#x8BC6;&#x522B;&#x5668;&#x5BF9;&#x5E94;&#x4E00;&#x4E2A;GestureRecognizer&#x7684;&#x5B50;&#x7C7B;&#xFF0C;Flutter&#x5B9E;&#x73B0;&#x4E86;&#x4E30;&#x5BCC;&#x7684;&#x624B;&#x52BF;&#x8BC6;&#x522B;&#x5668;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x4F7F;&#x7528;&#x3002;</p>
<h4 id="&#x793A;&#x4F8B;">&#x793A;&#x4F8B;</h4>
<p>&#x5047;&#x8BBE;&#x6211;&#x4EEC;&#x8981;&#x7ED9;&#x4E00;&#x6BB5;&#x5BCC;&#x6587;&#x672C;&#xFF08;RichText&#xFF09;&#x7684;&#x4E0D;&#x540C;&#x90E8;&#x5206;&#x5206;&#x522B;&#x6DFB;&#x52A0;&#x70B9;&#x51FB;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x5668;&#xFF0C;&#x4F46;&#x662F;TextSpan&#x5E76;&#x4E0D;&#x662F;&#x4E00;&#x4E2A;Widget&#xFF0C;&#x8FD9;&#x65F6;&#x6211;&#x4EEC;&#x4E0D;&#x80FD;&#x7528;GestureDetector&#xFF0C;&#x4F46;TextSpan&#x6709;&#x4E00;&#x4E2A;<code>recognizer</code>&#x5C5E;&#x6027;&#xFF0C;&#x5B83;&#x53EF;&#x4EE5;&#x63A5;&#x6536;&#x4E00;&#x4E2A;GestureRecognizer&#xFF0C;&#x5047;&#x8BBE;&#x6211;&#x4EEC;&#x5728;&#x70B9;&#x51FB;&#x65F6;&#x7ED9;&#x6587;&#x672C;&#x53D8;&#x8272;:</p>
<pre class="language-"><code class="lang-dart"><span class="token keyword">import</span> <span class="token string">&apos;package:flutter/gestures.dart&apos;</span><span class="token punctuation">;</span>

<span class="token keyword">class</span> <span class="token class-name">_GestureRecognizerTestRouteState</span>
    <span class="token keyword">extends</span> <span class="token class-name">State</span><span class="token operator">&lt;</span>_GestureRecognizerTestRoute<span class="token operator">&gt;</span> <span class="token punctuation">{</span>
  TapGestureRecognizer _tapGestureRecognizer <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">TapGestureRecognizer</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  bool _toggle <span class="token operator">=</span> <span class="token boolean">false</span><span class="token punctuation">;</span> <span class="token comment">//&#x53D8;&#x8272;&#x5F00;&#x5173;</span>

  <span class="token metadata symbol">@override</span>
  <span class="token keyword">void</span> <span class="token function">dispose</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
     <span class="token comment">//&#x7528;&#x5230;GestureRecognizer&#x7684;&#x8BDD;&#x4E00;&#x5B9A;&#x8981;&#x8C03;&#x7528;&#x5176;dispose&#x65B9;&#x6CD5;&#x91CA;&#x653E;&#x8D44;&#x6E90;</span>
    _tapGestureRecognizer<span class="token punctuation">.</span><span class="token function">dispose</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">super</span><span class="token punctuation">.</span><span class="token function">dispose</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>

  <span class="token metadata symbol">@override</span>
  Widget <span class="token function">build</span><span class="token punctuation">(</span>BuildContext context<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token function">Center</span><span class="token punctuation">(</span>
      child<span class="token punctuation">:</span> Text<span class="token punctuation">.</span><span class="token function">rich</span><span class="token punctuation">(</span>
          <span class="token function">TextSpan</span><span class="token punctuation">(</span>
              children<span class="token punctuation">:</span> <span class="token punctuation">[</span>
                <span class="token function">TextSpan</span><span class="token punctuation">(</span>text<span class="token punctuation">:</span> <span class="token string">&quot;&#x4F60;&#x597D;&#x4E16;&#x754C;&quot;</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
                <span class="token function">TextSpan</span><span class="token punctuation">(</span>
                  text<span class="token punctuation">:</span> <span class="token string">&quot;&#x70B9;&#x6211;&#x53D8;&#x8272;&quot;</span><span class="token punctuation">,</span>
                  style<span class="token punctuation">:</span> <span class="token function">TextStyle</span><span class="token punctuation">(</span>
                      fontSize<span class="token punctuation">:</span> <span class="token number">30.0</span><span class="token punctuation">,</span>
                      color<span class="token punctuation">:</span> _toggle <span class="token operator">?</span> Colors<span class="token punctuation">.</span>blue <span class="token punctuation">:</span> Colors<span class="token punctuation">.</span>red
                  <span class="token punctuation">)</span><span class="token punctuation">,</span>
                  recognizer<span class="token punctuation">:</span> _tapGestureRecognizer
                    <span class="token punctuation">.</span><span class="token punctuation">.</span>onTap <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                      <span class="token function">setState</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                        _toggle <span class="token operator">=</span> <span class="token operator">!</span>_toggle<span class="token punctuation">;</span>
                      <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                    <span class="token punctuation">}</span><span class="token punctuation">,</span>
                <span class="token punctuation">)</span><span class="token punctuation">,</span>
                <span class="token function">TextSpan</span><span class="token punctuation">(</span>text<span class="token punctuation">:</span> <span class="token string">&quot;&#x4F60;&#x597D;&#x4E16;&#x754C;&quot;</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
              <span class="token punctuation">]</span>
          <span class="token punctuation">)</span>
      <span class="token punctuation">)</span><span class="token punctuation">,</span>
    <span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x8FD0;&#x884C;&#x6548;&#x679C;&#xFF1A;</p>
<p><img src="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action@1.0/docs/imgs/image-20180914175603383.png" alt="image-20180914175603383"></p>
<p>&#x6CE8;&#x610F;&#xFF1A;&#x4F7F;&#x7528;GestureRecognizer&#x540E;&#x4E00;&#x5B9A;&#x8981;&#x8C03;&#x7528;&#x5176;<code>dispose()</code>&#x65B9;&#x6CD5;&#x6765;&#x91CA;&#x653E;&#x8D44;&#x6E90;&#xFF08;&#x4E3B;&#x8981;&#x662F;&#x53D6;&#x6D88;&#x5185;&#x90E8;&#x7684;&#x8BA1;&#x65F6;&#x5668;&#xFF09;&#x3002;</p>
<h3 id="&#x624B;&#x52BF;&#x7ADE;&#x4E89;&#x4E0E;&#x51B2;&#x7A81;">&#x624B;&#x52BF;&#x7ADE;&#x4E89;&#x4E0E;&#x51B2;&#x7A81;</h3>
<h4 id="&#x7ADE;&#x4E89;">&#x7ADE;&#x4E89;</h4>
<p>&#x5982;&#x679C;&#x5728;&#x4E0A;&#x4F8B;&#x4E2D;&#x6211;&#x4EEC;&#x540C;&#x65F6;&#x76D1;&#x542C;&#x6C34;&#x5E73;&#x548C;&#x5782;&#x76F4;&#x65B9;&#x5411;&#x7684;&#x62D6;&#x52A8;&#x4E8B;&#x4EF6;&#xFF0C;&#x90A3;&#x4E48;&#x6211;&#x4EEC;&#x659C;&#x7740;&#x62D6;&#x52A8;&#x65F6;&#x54EA;&#x4E2A;&#x65B9;&#x5411;&#x4F1A;&#x751F;&#x6548;&#xFF1F;&#x5B9E;&#x9645;&#x4E0A;&#x53D6;&#x51B3;&#x4E8E;&#x7B2C;&#x4E00;&#x6B21;&#x79FB;&#x52A8;&#x65F6;&#x4E24;&#x4E2A;&#x8F74;&#x4E0A;&#x7684;&#x4F4D;&#x79FB;&#x5206;&#x91CF;&#xFF0C;&#x54EA;&#x4E2A;&#x8F74;&#x7684;&#x5927;&#xFF0C;&#x54EA;&#x4E2A;&#x8F74;&#x5728;&#x672C;&#x6B21;&#x6ED1;&#x52A8;&#x4E8B;&#x4EF6;&#x7ADE;&#x4E89;&#x4E2D;&#x5C31;&#x80DC;&#x51FA;&#x3002;&#x5B9E;&#x9645;&#x4E0A;Flutter&#x4E2D;&#x7684;&#x624B;&#x52BF;&#x8BC6;&#x522B;&#x5F15;&#x5165;&#x4E86;&#x4E00;&#x4E2A;Arena&#x7684;&#x6982;&#x5FF5;&#xFF0C;Arena&#x76F4;&#x8BD1;&#x4E3A;&#x201C;&#x7ADE;&#x6280;&#x573A;&#x201D;&#x7684;&#x610F;&#x601D;&#xFF0C;&#x6BCF;&#x4E00;&#x4E2A;&#x624B;&#x52BF;&#x8BC6;&#x522B;&#x5668;&#xFF08;GestureRecognizer&#xFF09;&#x90FD;&#x662F;&#x4E00;&#x4E2A;&#x201C;&#x7ADE;&#x4E89;&#x8005;&#x201D;&#xFF08;GestureArenaMember&#xFF09;&#xFF0C;&#x5F53;&#x53D1;&#x751F;&#x6ED1;&#x52A8;&#x4E8B;&#x4EF6;&#x65F6;&#xFF0C;&#x4ED6;&#x4EEC;&#x90FD;&#x8981;&#x5728;&#x201C;&#x7ADE;&#x6280;&#x573A;&#x201D;&#x53BB;&#x7ADE;&#x4E89;&#x672C;&#x6B21;&#x4E8B;&#x4EF6;&#x7684;&#x5904;&#x7406;&#x6743;&#xFF0C;&#x800C;&#x6700;&#x7EC8;&#x53EA;&#x6709;&#x4E00;&#x4E2A;&#x201C;&#x7ADE;&#x4E89;&#x8005;&#x201D;&#x4F1A;&#x80DC;&#x51FA;(win)&#x3002;&#x4F8B;&#x5982;&#xFF0C;&#x5047;&#x8BBE;&#x6709;&#x4E00;&#x4E2A;ListView&#xFF0C;&#x5B83;&#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x5B50;Widget&#x4E5F;&#x662F;ListView&#xFF0C;&#x5982;&#x679C;&#x73B0;&#x5728;&#x6ED1;&#x52A8;&#x8FD9;&#x4E2A;&#x5B50;ListView&#xFF0C;&#x7236;ListView&#x4F1A;&#x52A8;&#x5417;&#xFF1F;&#x7B54;&#x6848;&#x662F;&#x5426;&#x5B9A;&#x7684;&#xFF0C;&#x8FD9;&#x65F6;&#x53EA;&#x6709;&#x5B50;Widget&#x4F1A;&#x52A8;&#xFF0C;&#x56E0;&#x4E3A;&#x8FD9;&#x65F6;&#x5B50;Widget&#x4F1A;&#x80DC;&#x51FA;&#x800C;&#x83B7;&#x5F97;&#x6ED1;&#x52A8;&#x4E8B;&#x4EF6;&#x7684;&#x5904;&#x7406;&#x6743;&#x3002;</p>
<p><strong>&#x793A;&#x4F8B;</strong></p>
<p>&#x6211;&#x4EEC;&#x4EE5;&#x62D6;&#x52A8;&#x624B;&#x52BF;&#x4E3A;&#x4F8B;&#xFF0C;&#x540C;&#x65F6;&#x8BC6;&#x522B;&#x6C34;&#x5E73;&#x548C;&#x5782;&#x76F4;&#x65B9;&#x5411;&#x7684;&#x62D6;&#x52A8;&#x624B;&#x52BF;&#xFF0C;&#x5F53;&#x7528;&#x6237;&#x6309;&#x4E0B;&#x624B;&#x6307;&#x65F6;&#x5C31;&#x4F1A;&#x89E6;&#x53D1;&#x7ADE;&#x4E89;&#xFF08;&#x6C34;&#x5E73;&#x65B9;&#x5411;&#x548C;&#x5782;&#x76F4;&#x65B9;&#x5411;&#xFF09;&#xFF0C;&#x4E00;&#x65E6;&#x67D0;&#x4E2A;&#x65B9;&#x5411;&#x201C;&#x83B7;&#x80DC;&#x201D;&#xFF0C;&#x5219;&#x76F4;&#x5230;&#x5F53;&#x6B21;&#x62D6;&#x52A8;&#x624B;&#x52BF;&#x7ED3;&#x675F;&#x90FD;&#x4F1A;&#x6CBF;&#x7740;&#x8BE5;&#x65B9;&#x5411;&#x79FB;&#x52A8;&#x3002;&#x4EE3;&#x7801;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre class="language-"><code class="lang-dart"><span class="token keyword">import</span> <span class="token string">&apos;package:flutter/material.dart&apos;</span><span class="token punctuation">;</span>

<span class="token keyword">class</span> <span class="token class-name">BothDirectionTestRoute</span> <span class="token keyword">extends</span> <span class="token class-name">StatefulWidget</span> <span class="token punctuation">{</span>
  <span class="token metadata symbol">@override</span>
  BothDirectionTestRouteState <span class="token function">createState</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">&gt;</span>
      <span class="token keyword">new</span> <span class="token class-name">BothDirectionTestRouteState</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token keyword">class</span> <span class="token class-name">BothDirectionTestRouteState</span> <span class="token keyword">extends</span> <span class="token class-name">State</span><span class="token operator">&lt;</span>BothDirectionTestRoute<span class="token operator">&gt;</span> <span class="token punctuation">{</span>
  double _top <span class="token operator">=</span> <span class="token number">0.0</span><span class="token punctuation">;</span>
  double _left <span class="token operator">=</span> <span class="token number">0.0</span><span class="token punctuation">;</span>

  <span class="token metadata symbol">@override</span>
  Widget <span class="token function">build</span><span class="token punctuation">(</span>BuildContext context<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token function">Stack</span><span class="token punctuation">(</span>
      children<span class="token punctuation">:</span> <span class="token operator">&lt;</span>Widget<span class="token operator">&gt;</span><span class="token punctuation">[</span>
        <span class="token function">Positioned</span><span class="token punctuation">(</span>
          top<span class="token punctuation">:</span> _top<span class="token punctuation">,</span>
          left<span class="token punctuation">:</span> _left<span class="token punctuation">,</span>
          child<span class="token punctuation">:</span> <span class="token function">GestureDetector</span><span class="token punctuation">(</span>
            child<span class="token punctuation">:</span> <span class="token function">CircleAvatar</span><span class="token punctuation">(</span>child<span class="token punctuation">:</span> <span class="token function">Text</span><span class="token punctuation">(</span><span class="token string">&quot;A&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
            <span class="token comment">//&#x5782;&#x76F4;&#x65B9;&#x5411;&#x62D6;&#x52A8;&#x4E8B;&#x4EF6;</span>
            onVerticalDragUpdate<span class="token punctuation">:</span> <span class="token punctuation">(</span>DragUpdateDetails details<span class="token punctuation">)</span> <span class="token punctuation">{</span>
              <span class="token function">setState</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                _top <span class="token operator">+=</span> details<span class="token punctuation">.</span>delta<span class="token punctuation">.</span>dy<span class="token punctuation">;</span>
              <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span><span class="token punctuation">,</span>
            onHorizontalDragUpdate<span class="token punctuation">:</span> <span class="token punctuation">(</span>DragUpdateDetails details<span class="token punctuation">)</span> <span class="token punctuation">{</span>
              <span class="token function">setState</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                _left <span class="token operator">+=</span> details<span class="token punctuation">.</span>delta<span class="token punctuation">.</span>dx<span class="token punctuation">;</span>
              <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span><span class="token punctuation">,</span>
          <span class="token punctuation">)</span><span class="token punctuation">,</span>
        <span class="token punctuation">)</span>
      <span class="token punctuation">]</span><span class="token punctuation">,</span>
    <span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x6B64;&#x793A;&#x4F8B;&#x8FD0;&#x884C;&#x540E;&#xFF0C;&#x6BCF;&#x6B21;&#x62D6;&#x52A8;&#x53EA;&#x4F1A;&#x6CBF;&#x4E00;&#x4E2A;&#x65B9;&#x5411;&#x79FB;&#x52A8;&#xFF08;&#x6C34;&#x5E73;&#x6216;&#x5782;&#x76F4;&#xFF09;&#xFF0C;&#x800C;&#x7ADE;&#x4E89;&#x53D1;&#x751F;&#x5728;&#x624B;&#x6307;&#x6309;&#x4E0B;&#x540E;&#x9996;&#x6B21;&#x79FB;&#x52A8;&#xFF08;move&#xFF09;&#x65F6;&#xFF0C;&#x6B64;&#x4F8B;&#x4E2D;&#x5177;&#x4F53;&#x7684;&#x201C;&#x83B7;&#x80DC;&#x201D;&#x6761;&#x4EF6;&#x662F;&#xFF1A;&#x9996;&#x6B21;&#x79FB;&#x52A8;&#x65F6;&#x7684;&#x4F4D;&#x79FB;&#x5728;&#x6C34;&#x5E73;&#x548C;&#x5782;&#x76F4;&#x65B9;&#x5411;&#x4E0A;&#x7684;&#x5206;&#x91CF;&#x5927;&#x7684;&#x4E00;&#x4E2A;&#x83B7;&#x80DC;&#x3002;</p>
<h4 id="&#x624B;&#x52BF;&#x51B2;&#x7A81;">&#x624B;&#x52BF;&#x51B2;&#x7A81;</h4>
<p>&#x7531;&#x4E8E;&#x624B;&#x52BF;&#x7ADE;&#x4E89;&#x6700;&#x7EC8;&#x53EA;&#x6709;&#x4E00;&#x4E2A;&#x80DC;&#x51FA;&#x8005;&#xFF0C;&#x6240;&#x4EE5;&#xFF0C;&#x5F53;&#x6709;&#x591A;&#x4E2A;&#x624B;&#x52BF;&#x8BC6;&#x522B;&#x5668;&#x65F6;&#xFF0C;&#x53EF;&#x80FD;&#x4F1A;&#x4EA7;&#x751F;&#x51B2;&#x7A81;&#x3002;&#x5047;&#x8BBE;&#x6709;&#x4E00;&#x4E2A;widget&#xFF0C;&#x5B83;&#x53EF;&#x4EE5;&#x5DE6;&#x53F3;&#x62D6;&#x52A8;&#xFF0C;&#x73B0;&#x5728;&#x6211;&#x4EEC;&#x4E5F;&#x60F3;&#x68C0;&#x6D4B;&#x5728;&#x5B83;&#x4E0A;&#x9762;&#x624B;&#x6307;&#x6309;&#x4E0B;&#x548C;&#x62AC;&#x8D77;&#x7684;&#x4E8B;&#x4EF6;&#xFF0C;&#x4EE3;&#x7801;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre class="language-"><code class="lang-dart"><span class="token keyword">class</span> <span class="token class-name">GestureConflictTestRouteState</span> <span class="token keyword">extends</span> <span class="token class-name">State</span><span class="token operator">&lt;</span>GestureConflictTestRoute<span class="token operator">&gt;</span> <span class="token punctuation">{</span>
  double _left <span class="token operator">=</span> <span class="token number">0.0</span><span class="token punctuation">;</span>
  <span class="token metadata symbol">@override</span>
  Widget <span class="token function">build</span><span class="token punctuation">(</span>BuildContext context<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token function">Stack</span><span class="token punctuation">(</span>
      children<span class="token punctuation">:</span> <span class="token operator">&lt;</span>Widget<span class="token operator">&gt;</span><span class="token punctuation">[</span>
        <span class="token function">Positioned</span><span class="token punctuation">(</span>
          left<span class="token punctuation">:</span> _left<span class="token punctuation">,</span>
          child<span class="token punctuation">:</span> <span class="token function">GestureDetector</span><span class="token punctuation">(</span>
              child<span class="token punctuation">:</span> <span class="token function">CircleAvatar</span><span class="token punctuation">(</span>child<span class="token punctuation">:</span> <span class="token function">Text</span><span class="token punctuation">(</span><span class="token string">&quot;A&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token comment">//&#x8981;&#x62D6;&#x52A8;&#x548C;&#x70B9;&#x51FB;&#x7684;widget</span>
              onHorizontalDragUpdate<span class="token punctuation">:</span> <span class="token punctuation">(</span>DragUpdateDetails details<span class="token punctuation">)</span> <span class="token punctuation">{</span>
                <span class="token function">setState</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                  _left <span class="token operator">+=</span> details<span class="token punctuation">.</span>delta<span class="token punctuation">.</span>dx<span class="token punctuation">;</span>
                <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
              <span class="token punctuation">}</span><span class="token punctuation">,</span>
              onHorizontalDragEnd<span class="token punctuation">:</span> <span class="token punctuation">(</span>details<span class="token punctuation">)</span><span class="token punctuation">{</span>
                <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&quot;onHorizontalDragEnd&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
              <span class="token punctuation">}</span><span class="token punctuation">,</span>
              onTapDown<span class="token punctuation">:</span> <span class="token punctuation">(</span>details<span class="token punctuation">)</span><span class="token punctuation">{</span>
                <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&quot;down&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
              <span class="token punctuation">}</span><span class="token punctuation">,</span>
              onTapUp<span class="token punctuation">:</span> <span class="token punctuation">(</span>details<span class="token punctuation">)</span><span class="token punctuation">{</span>
                <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&quot;up&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
              <span class="token punctuation">}</span><span class="token punctuation">,</span>
          <span class="token punctuation">)</span><span class="token punctuation">,</span>
        <span class="token punctuation">)</span>
      <span class="token punctuation">]</span><span class="token punctuation">,</span>
    <span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x73B0;&#x5728;&#x6211;&#x4EEC;&#x6309;&#x4F4F;&#x5706;&#x5F62;&#x201C;A&#x201D;&#x62D6;&#x52A8;&#x7136;&#x540E;&#x62AC;&#x8D77;&#x624B;&#x6307;&#xFF0C;&#x63A7;&#x5236;&#x53F0;&#x65E5;&#x5FD7;&#x5982;&#x4E0B;:</p>
<pre class="language-"><code>I/flutter (17539): down
I/flutter (17539): onHorizontalDragEnd
</code></pre><p>&#x6211;&#x4EEC;&#x53D1;&#x73B0;&#x6CA1;&#x6709;&#x6253;&#x5370;&quot;up&quot;&#xFF0C;&#x8FD9;&#x662F;&#x56E0;&#x4E3A;&#x5728;&#x62D6;&#x52A8;&#x65F6;&#xFF0C;&#x521A;&#x5F00;&#x59CB;&#x6309;&#x4E0B;&#x624B;&#x6307;&#x65F6;&#x5728;&#x6CA1;&#x6709;&#x79FB;&#x52A8;&#x65F6;&#xFF0C;&#x62D6;&#x52A8;&#x624B;&#x52BF;&#x8FD8;&#x6CA1;&#x6709;&#x5B8C;&#x6574;&#x7684;&#x8BED;&#x4E49;&#xFF0C;&#x6B64;&#x65F6;TapDown&#x624B;&#x52BF;&#x80DC;&#x51FA;(win)&#xFF0C;&#x6B64;&#x65F6;&#x6253;&#x5370;&quot;down&quot;&#xFF0C;&#x800C;&#x62D6;&#x52A8;&#x65F6;&#xFF0C;&#x62D6;&#x52A8;&#x624B;&#x52BF;&#x4F1A;&#x80DC;&#x51FA;&#xFF0C;&#x5F53;&#x624B;&#x6307;&#x62AC;&#x8D77;&#x65F6;&#xFF0C;<code>onHorizontalDragEnd</code> &#x548C; <code>onTapUp</code>&#x53D1;&#x751F;&#x4E86;&#x51B2;&#x7A81;&#xFF0C;&#x4F46;&#x662F;&#x56E0;&#x4E3A;&#x662F;&#x5728;&#x62D6;&#x52A8;&#x7684;&#x8BED;&#x4E49;&#x4E2D;&#xFF0C;&#x6240;&#x4EE5;<code>onHorizontalDragEnd</code>&#x80DC;&#x51FA;&#xFF0C;&#x6240;&#x4EE5;&#x5C31;&#x4F1A;&#x6253;&#x5370; &#x201C;onHorizontalDragEnd&#x201D;&#x3002;&#x5982;&#x679C;&#x6211;&#x4EEC;&#x7684;&#x4EE3;&#x7801;&#x903B;&#x8F91;&#x4E2D;&#xFF0C;&#x5BF9;&#x4E8E;&#x624B;&#x6307;&#x6309;&#x4E0B;&#x548C;&#x62AC;&#x8D77;&#x662F;&#x5F3A;&#x4F9D;&#x8D56;&#x7684;&#xFF0C;&#x6BD4;&#x5982;&#x5728;&#x4E00;&#x4E2A;&#x8F6E;&#x64AD;&#x56FE;&#x7EC4;&#x4EF6;&#x4E2D;&#xFF0C;&#x6211;&#x4EEC;&#x5E0C;&#x671B;&#x624B;&#x6307;&#x6309;&#x4E0B;&#x65F6;&#xFF0C;&#x6682;&#x505C;&#x8F6E;&#x64AD;&#xFF0C;&#x800C;&#x62AC;&#x8D77;&#x65F6;&#x6062;&#x590D;&#x8F6E;&#x64AD;&#xFF0C;&#x4F46;&#x662F;&#x7531;&#x4E8E;&#x8F6E;&#x64AD;&#x56FE;&#x7EC4;&#x4EF6;&#x4E2D;&#x672C;&#x8EAB;&#x53EF;&#x80FD;&#x5DF2;&#x7ECF;&#x5904;&#x7406;&#x4E86;&#x62D6;&#x52A8;&#x624B;&#x52BF;&#xFF08;&#x652F;&#x6301;&#x624B;&#x52A8;&#x6ED1;&#x52A8;&#x5207;&#x6362;&#xFF09;&#xFF0C;&#x751A;&#x81F3;&#x53EF;&#x80FD;&#x4E5F;&#x652F;&#x6301;&#x4E86;&#x7F29;&#x653E;&#x624B;&#x52BF;&#xFF0C;&#x8FD9;&#x65F6;&#x6211;&#x4EEC;&#x5982;&#x679C;&#x5728;&#x5916;&#x90E8;&#x518D;&#x7528;<code>onTapDown</code>&#x3001;<code>onTapUp</code>&#x6765;&#x76D1;&#x542C;&#x7684;&#x8BDD;&#x662F;&#x4E0D;&#x884C;&#x7684;&#x3002;&#x8FD9;&#x65F6;&#x6211;&#x4EEC;&#x5E94;&#x8BE5;&#x600E;&#x4E48;&#x505A;&#xFF1F;&#x5176;&#x5B9E;&#x5F88;&#x7B80;&#x5355;&#xFF0C;&#x901A;&#x8FC7;Listener&#x76D1;&#x542C;&#x539F;&#x59CB;&#x6307;&#x9488;&#x4E8B;&#x4EF6;&#x5C31;&#x884C;&#xFF1A;</p>
<pre class="language-"><code class="lang-dart"><span class="token function">Positioned</span><span class="token punctuation">(</span>
  top<span class="token punctuation">:</span><span class="token number">80.0</span><span class="token punctuation">,</span>
  left<span class="token punctuation">:</span> _leftB<span class="token punctuation">,</span>
  child<span class="token punctuation">:</span> <span class="token function">Listener</span><span class="token punctuation">(</span>
    onPointerDown<span class="token punctuation">:</span> <span class="token punctuation">(</span>details<span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&quot;down&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    onPointerUp<span class="token punctuation">:</span> <span class="token punctuation">(</span>details<span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token comment">//&#x4F1A;&#x89E6;&#x53D1;</span>
      <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&quot;up&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    child<span class="token punctuation">:</span> <span class="token function">GestureDetector</span><span class="token punctuation">(</span>
      child<span class="token punctuation">:</span> <span class="token function">CircleAvatar</span><span class="token punctuation">(</span>child<span class="token punctuation">:</span> <span class="token function">Text</span><span class="token punctuation">(</span><span class="token string">&quot;B&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
      onHorizontalDragUpdate<span class="token punctuation">:</span> <span class="token punctuation">(</span>DragUpdateDetails details<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token function">setState</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
          _leftB <span class="token operator">+=</span> details<span class="token punctuation">.</span>delta<span class="token punctuation">.</span>dx<span class="token punctuation">;</span>
        <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token punctuation">}</span><span class="token punctuation">,</span>
      onHorizontalDragEnd<span class="token punctuation">:</span> <span class="token punctuation">(</span>details<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&quot;onHorizontalDragEnd&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token punctuation">)</span><span class="token punctuation">,</span>
  <span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token punctuation">)</span>
</code></pre>
<p>&#x603B;&#x7ED3;&#xFF1A;</p>
<p>&#x624B;&#x52BF;&#x51B2;&#x7A81;&#x53EA;&#x662F;&#x624B;&#x52BF;&#x7EA7;&#x522B;&#x7684;&#xFF0C;&#x800C;&#x624B;&#x52BF;&#x662F;&#x5BF9;&#x539F;&#x59CB;&#x6307;&#x9488;&#x7684;&#x8BED;&#x4E49;&#x5316;&#x7684;&#x8BC6;&#x522B;&#xFF0C;&#x6240;&#x4EE5;&#x5728;&#x9047;&#x5230;&#x590D;&#x6742;&#x7684;&#x51B2;&#x7A81;&#x573A;&#x666F;&#x65F6;&#xFF0C;&#x90FD;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;Listener&#x76F4;&#x63A5;&#x8BC6;&#x522B;&#x539F;&#x59CB;&#x6307;&#x9488;&#x4E8B;&#x4EF6;&#x6765;&#x89E3;&#x51B3;&#x51B2;&#x7A81;&#x3002;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="listener.html" class="navigation navigation-prev " aria-label="Previous page: 原始指针事件处理">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="eventbus.html" class="navigation navigation-next " aria-label="Next page: 全局事件总线">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"手势识别","level":"1.9.2","depth":2,"next":{"title":"全局事件总线","level":"1.9.3","depth":2,"path":"chapter8/eventbus.md","ref":"chapter8/eventbus.md","articles":[]},"previous":{"title":"原始指针事件处理","level":"1.9.1","depth":2,"path":"chapter8/listener.md","ref":"chapter8/listener.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-search","search-pro","ace","splitter","toggle-chapters","prism","donate","-highlight"],"root":"docs","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"prism":{"lang":{"shell":"bash"}},"ace":{},"splitter":{},"search-pro":{"cutWordLib":"nodejieba","defineWord":["Gitbook Use"]},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"donate":{"alipay":"","alipayText":"支付宝打赏","button":"赏","title":"","wechat":"https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action@1.0.3/docs/imgs/pay.jpeg","wechatText":"微信打赏"},"fontsettings":{"theme":"white","family":"sans","size":2},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"toggle-chapters":{}},"theme":"default","author":"wendux 824783146@qq.com","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"《Flutter实战》","language":"zh-hans","links":{"sharing":{"all":null,"facebook":null,"google":null,"twitter":null,"weibo":null},"sidebar":{"<div><img height=20 style='position:relative; top:5px; padding-right:5px ' src='https://cdn.jsdelivr.net/gh/flutterchina/website@1.0/images/favicon.png'/> Flutter中文网</div>":"https://flutterchina.club"}},"gitbook":"*","description":"记录Gitbook的配置和一些插件的使用"},"file":{"path":"chapter8/gesture.md","mtime":"2019-01-02T10:06:06.488Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-05-14T10:32:57.346Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>



    <script src="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/gitbook.js"></script>
    <script src="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/theme.js"></script>
    
        
        <script src="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/gitbook-plugin-ace/ace/ace.js"></script>
        
    
        
        <script src="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/gitbook-plugin-ace/ace.js"></script>
        
    
        
        <script src="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/gitbook-plugin-toggle-chapters/toggle.js"></script>
        
    
        
        <script src="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/gitbook-plugin-donate/plugin.js"></script>
        
    
        
        <script src="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    


<script>
    var _hmt = _hmt || [];
    $("#bd").remove();
    (function () {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?170231fea4f81697eb046edc1a91fe5b";
        var s = document.getElementsByTagName("script")[0];
        hm.id = "bd"
        s.parentNode.insertBefore(hm, s);
    })();

    function init() {
        var p = location.pathname;
        _hmt.push(['_trackPageview', p]);
        if (p[p.length - 1] === '/') {
            p += "index.md"
        } else {
            p = p.split(".")[0] + ".md";
        }
        p = "https://github.com/flutterchina/flutter-in-action/blob/master/docs" + p;
        $(".pull-right .fa-edit").parent("a").attr("href", p);
        $("table").wrap("<div style='overflow: auto'></div>");
        //百度统计
        var e = /([http|https]:\/\/[a-zA-Z0-9\_\.]+\.baidu\.com)/gi, r = window.location.href,
            t = document.referrer;
        if (!e.test(r)) {
            var o = "https://sp0.baidu.com/9_Q4simg2RQJ8t7jm9iCKT-xh_/s.gif";
            t ? (o += "?r=" + encodeURIComponent(document.referrer), r && (o += "&l=" + r)) : r && (o += "?l=" + r);
            var i = new Image;
            i.src = o
        }
        $(".copyright").remove();
        $("<div class='copyright'> 本书仍在勘误阶段，请勿以任何形式私自传播，作者保留对本书的版权。</div>").appendTo(".page-inner");
    }

    function hookAPI(api, ob, fn) {
        return function () {
            var result = api.apply(ob, [].slice.call(arguments));

            setTimeout(fn, 1000);
            return result;
        }
    }

    function addAD() {
        if (location.href !== 'https://book.flutterchina.club/' && $("#book-search-results .ad").length == 0) {
            var id=Math.ceil(Math.random()*10)%2;
            $(".ad"+id).clone().hide().fadeIn().prependTo("#book-search-results")
            setTimeout(function () {
                $(".body-inner").animate({scrollTop: 0}, 200)
            }, 800);
        }
    }

    function _track(p,url) {
        _hmt.push(['_trackEvent', 'ad', 'click', p]);
        setTimeout(function () {
            location.href = url
        }, 100);
    }

    // setInterval(addAD, 300);

    init();


    if (history.pushState) {
        history.pushState = hookAPI(history.pushState, history, init);
    }

</script>
</body>

</html>

